package com.wm.service.imp;

import java.util.List;

import com.wm.bean.ApplyRestaurant;
import com.wm.bean.Area;
import com.wm.bean.City;
import com.wm.bean.User;
import com.wm.bean.UserComment;
import com.wm.bean.UserScriptorium;
import com.wm.dao.AddressDAO;
import com.wm.dao.ApplyRestaurantDAO;
import com.wm.dao.AreaDAO;
import com.wm.dao.CityDAO;
import com.wm.dao.UserCommentDAO;
import com.wm.dao.UserDAO;
import com.wm.dao.UserScriptoriumDAO;
import com.wm.service.ApplyRestaurantService;
import com.wm.service.UserCommentService;
import com.wm.service.UserScriptoriumService;
import com.wm.service.UserService;
import com.wm.service.web.PageList;
import com.wm.service.web.Pages;

/**
 * @author yangbo
 *
 * 2013-1-4
 */
public class ApplyRestaurantServiceImp implements ApplyRestaurantService {
	private ApplyRestaurantDAO applyRestaurantDAO;
	
	public ApplyRestaurantDAO getApplyRestaurantDAO() {
		return applyRestaurantDAO;
	}

	public void setApplyRestaurantDAO(ApplyRestaurantDAO applyRestaurantDAO) {
		this.applyRestaurantDAO = applyRestaurantDAO;
	}

	/**
	 * 保存ApplyRestaurant对象
	 * 
	 * @param ar
	 * 			ApplyRestaurant
	 * @return  ApplyRestaurant
	 * 			ApplyRestaurant
	 */
	public ApplyRestaurant saveApplyRestaurant(ApplyRestaurant ar){
		ar = this.getApplyRestaurantDAO().saveApplyRestaurant(ar);
		return ar;
	}
	
	/**
	 * 更新ApplyRestaurant对象
	 * 
	 * @param ar
	 * 			ApplyRestaurant
	 * @return  ApplyRestaurant
	 * 			ApplyRestaurant
	 */
	public ApplyRestaurant updateApplyRestaurant(ApplyRestaurant ar){
		ar = this.getApplyRestaurantDAO().updateApplyRestaurant(ar);
		return ar;
	}
	
	/**
	 * 根据ID删除ApplyRestaurant对象
	 * 
	 * @param id
	 * 			long
	 */
	public void removeApplyRestaurantById(long id){
		this.getApplyRestaurantDAO().removeApplyRestaurantById(id);
	}
	
	/**
	 * 根据ID获取ApplyRestaurant对象
	 * 
	 * @param id
	 * 			long
	 * @return  ApplyRestaurant
	 * 			ApplyRestaurant
	 */
	public ApplyRestaurant findApplyRestaurantById(long id){
		return this.getApplyRestaurantDAO().findApplyRestaurantById(id);
	}
	
	/**
	 * 获取ApplyRestaurant对象列表
	 * 
	 * @param applyType
	 * 			int
	 * @param orderby
	 *            String
	 * @param ascOrDesc
	 *            int
	 * @param pages
	 * 			  Pages
	 * @return PageList
	 * 			ApplyRestaurant对象列表
	 */
	public PageList findApplyRestaurants(int applyType,String orderby, int ascOrDesc,Pages pages){
		PageList pl = new PageList();
        if (pages.getTotalNum() == -1) {
            pages.setTotalNum(this.getApplyRestaurantDAO().getApplyRestaurantNum(applyType));
        }
        pages.executeCount();
        if(pages.getTotalNum() == 0){
        	pl.setObjectList(null);
        	pl.setPages(pages);
        	return pl;
        }
		List l = this.getApplyRestaurantDAO().findApplyRestaurants(applyType, orderby, ascOrDesc,pages.getSpage(), pages.getPerPageNum());
		if(l == null || l.isEmpty()){
	   		 pl.setObjectList(null);
	   	     pl.setPages(pages);
	   		 return pl;
		}else{
			pl.setObjectList(l);
	        pl.setPages(pages);
	        return pl;
		}
	}
}
